package com.gao.io;

import java.io.*;

/**
 * @Author: ShanYuqing
 * @Version: v1.0
 */
public class CopyFile {
    public static void main(String[] args) throws IOException {
        File src = new File("D://晚风");
        File dest = new File("E://");
        copyFile(src, dest);
    }

    private static void copyFile(File src, File dest) throws IOException {
        File newDir = new File(dest, src.getName());
        newDir.mkdirs();
        File[] files = src.listFiles();
        for (File file : files) {
            if (file.isFile()) {
                FileInputStream f1 = new FileInputStream(file);
                FileOutputStream f2 = new FileOutputStream(new File(newDir, file.getName()));
                int i;
                byte[] bys = new byte[1024];
                while((i = f1.read(bys)) != -1) {
                    f2.write(bys,0,i);
                }
                f1.close();
                f2.close();
            }else{
                copyFile(file,newDir);
            }
        }

    }

}
